
$("#not-card-close").click(function () {
    clearInfo();
    $('#noCard').modal('hide')
});

function clearInfo() {
    $("#not-card-paperId").val("");
    $("#not-card-cardNo").val("");
    $("#not-card-cardUserName").val("");
    $("#not-card-cardBanlance").val("");
    $("#not-card-cardStateName").val("");
    $("#not-card-cardTypeName").val("");
    $("#not-card-refundamt").val("");
    $("#not-card-deposit").val("20");
    $("#not-card-refundamt-amt").text("20");
    //$("#paperPhoto").attr("src","");
}

var cardInfo;

function load_data(x){
    if(x === null || x === ''){
        $MB.n_danger("系统异常，请重新操作");
        $('#not-card').modal('hide')
    }
    var obj = new Object();
    obj.cardNo = x;
    $.post(ctx+"cardInfo/getNotCardInfoByCardNo",obj,function(r){
        if (r.code !== 0) {
            $MB.n_danger(r.msg);
            $('#not-card').modal('hide')
            return;
        }
        console.log(r.cardInfo);
        if(r.cardInfo === null){
            $MB.n_danger("查询不到该卡号信息，请重新操作！");
            $('#not-card').modal('hide')
            return;
        }
        if(r.cardInfo.length === 0){
            $MB.n_danger("查询不到该卡号信息，请重新操作！");
            $('#not-card').modal('hide')
            return;
        }
        $("#not-card-cardBanlance").val(r.cardInfo[0].cardBanlance);
        $("#not-card-paperId").val(r.cardInfo[0].paperId);
        $("#not-card-cardNo").val(r.cardInfo[0].cardNo);
        $("#not-card-cardUserName").val(r.cardInfo[0].cardUserName);
        $("#not-card-cardStateName").val(r.cardInfo[0].cardStateName);
        $("#not-card-cardTypeName").val(r.cardInfo[0].cardTypeName);
        cardInfo = r.cardInfo[0];
    });
}

$("#not-card-refundamt").on("input",function () {
    var refundamt = $("#not-card-refundamt").val();
    var deposit = $("#not-card-deposit").val();
    if(refundamt === null || refundamt === ''){
        refundamt = 0
    }
    if(deposit === null || deposit === ''){
        deposit = 0
    }
    var amt = Number(refundamt)+Number(deposit)
    $("#not-card-refundamt-amt").text(amt);
})

$("#not-card-deposit").on("input",function () {
    var refundamt = $("#not-card-refundamt").val();
    var deposit = $("#not-card-deposit").val();
    if(refundamt === null || refundamt === ''){
        refundamt = 0
    }
    if(deposit === null || deposit === ''){
        deposit = 0
    }
    var amt = Number(refundamt)+Number(deposit)
    $("#not-card-refundamt-amt").text(amt);
})

$("#not-card-save").click(function () {
    console.log("not-card-save")
    var cardNo = $("#not-card-cardNo").val();
    if(cardNo === null){
        $MB.n_danger("卡号读取失败，请重新操作");
        $('#card-read').modal('hide')
        return;
    }
    /*if(cardInfo.cardState != 0){
        $MB.n_danger("卡状态异常，无法做退卡登记！");
        $('#card-read').modal('hide')
        return;
    }*/
    if(cardInfo.cardBanlance === null){
        $MB.n_danger("系统卡余额读取失败，请重庆操作");
        $('#card-read').modal('hide')
        return;
    }
    var refundamt = $("#not-card-refundamt").val();
    if(refundamt === null || refundamt === ''){
        $MB.n_danger("请输入退款金额");
        //$('#card-read').modal('hide')
        return;
    }
    var deposit = $("#not-card-deposit").val();
    if(deposit === null || deposit === ''){
        $MB.n_danger("请输入退款押金金额");
        return;
    }
    var par = new Object()
    par.cardNo = cardNo;
    par.cardBanlance = cardInfo.cardBanlance;
    par.refundamt = refundamt;
    par.deposit = deposit;
    $.post(ctx+"cardInfo/commitRefundCard",par,function (r) {
        if (r.code !== 0) {
            $MB.n_danger(r.msg);
            $('#card-read').modal('hide')
            return;
        }else{
            $MB.n_success("退卡信息已记录！");
            notCardPrint(r);
            $('#card-read').modal('hide')
            return;
        }
    });
})


function notCardPrint(r) {
    var LODOP; //声明为全局变量
    LODOP = getLodop(document.getElementById('LODOP_X'),document.getElementById('LODOP_EM'));
    LODOP.NEWPAGEA();
    //LODOP.ADD_PRINT_RECT(10,18,324,392,0,1);
    LODOP.ADD_PRINT_TEXT(20,15,258,54,"三亚一卡通服务凭证");
    LODOP.SET_PRINT_STYLEA(0,"FontName","微软雅黑");
    LODOP.SET_PRINT_STYLEA(0,"fontsize",12);

    LODOP.ADD_PRINT_TEXT(55,65,258,54,"退卡完成");
    LODOP.SET_PRINT_STYLEA(0,"fontsize",9);
    LODOP.SET_PRINT_STYLEA(0,"FontName","微软雅黑");

    LODOP.ADD_PRINT_TEXT(90,3,258,54,"凭证号："+r.data.refundordernum);
    LODOP.SET_PRINT_STYLEA(0,"fontsize",9);
    LODOP.SET_PRINT_STYLEA(0,"FontName","微软雅黑");

    LODOP.ADD_PRINT_TEXT(120,3,258,54,"卡号："+r.data.cardno);
    LODOP.SET_PRINT_STYLEA(0,"fontsize",9);
    LODOP.SET_PRINT_STYLEA(0,"FontName","微软雅黑");

    LODOP.ADD_PRINT_TEXT(150,3,258,54,"卡类型："+r.data.cardtypename);
    LODOP.SET_PRINT_STYLEA(0,"fontsize",9);
    LODOP.SET_PRINT_STYLEA(0,"FontName","微软雅黑");

    LODOP.ADD_PRINT_TEXT(180,3,258,54,"实退卡费："+r.data.deposit/100+"元");
    LODOP.SET_PRINT_STYLEA(0,"fontsize",9);
    LODOP.SET_PRINT_STYLEA(0,"FontName","微软雅黑")

    LODOP.ADD_PRINT_TEXT(210,3,258,54,"卡余额："+r.data.cardbanlance/100+"元");
    LODOP.SET_PRINT_STYLEA(0,"fontsize",9);
    LODOP.SET_PRINT_STYLEA(0,"FontName","微软雅黑")

    LODOP.ADD_PRINT_TEXT(240,3,258,54,"实退总金额："+r.data.refundamt/100+"元");
    LODOP.SET_PRINT_STYLEA(0,"fontsize",9);
    LODOP.SET_PRINT_STYLEA(0,"FontName","微软雅黑")

    LODOP.ADD_PRINT_TEXT(270,3,258,54,"操作人："+r.data.refundusername);
    LODOP.SET_PRINT_STYLEA(0,"fontsize",9);
    LODOP.SET_PRINT_STYLEA(0,"FontName","微软雅黑")

    LODOP.ADD_PRINT_TEXT(300,3,258,54,"退卡日期："+r.data.refunddate);
    LODOP.SET_PRINT_STYLEA(0,"fontsize",9);
    LODOP.SET_PRINT_STYLEA(0,"FontName","微软雅黑")

    //设定打印页面大小
    LODOP.SET_PRINT_PAGESIZE(3,590,55,"");
    LODOP.SET_PRINT_COPIES(2);
    LODOP.PRINT();
    //LODOP.PREVIEW();
    if (needCLodop()) {
        window.On_CLodop_Opened=function(){
            OpenPreview();
            window.On_CLodop_Opened=null;
        };
    } else
        window.onload = function(){
            OpenPreview();
        };
}